<!DOCTYPE html>
<html>
<head>
    <title>管理后台</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container py-4">
        <h1 class="mb-4">视频管理后台</h1>
        
        <!-- 上传表单 -->
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">上传视频</h5>
            </div>
            <div class="card-body">
                <form id="uploadForm" method="POST" enctype="multipart/form-data">
                    <div class="mb-3">
                        <label for="title" class="form-label">标题</label>
                        <input type="text" class="form-control" id="title" name="title" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="category" class="form-label">分类</label>
                        <select class="form-select" id="category" name="category_id" required>
                            <option value="">选择分类...</option>
                            {% for category in categories %}
                            <option value="{{ category.id }}">{{ category.name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    
                    <div class="mb-3">
                        <label for="cover" class="form-label">封面图片</label>
                        <input type="file" class="form-control" id="cover" name="cover" accept="image/*" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="video" class="form-label">视频文件</label>
                        <input type="file" class="form-control" id="video" name="video" accept="video/*" required>
                    </div>
                    
                    <button type="submit" class="btn btn-primary">上传</button>
                </form>
            </div>
        </div>
        
        <!-- 视频列表 -->
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">视频列表</h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>标题</th>
                                <th>分类</th>
                                <th>上传时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for video in videos %}
                            <tr>
                                <td>{{ video.title }}</td>
                                <td>{{ video.category.name if video.category else '未分类' }}</td>
                                <td>{{ video.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                                <td>
                                    <button class="btn btn-sm btn-danger" onclick="deleteVideo({{ video.id }})">删除</button>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 删除视频
        function deleteVideo(videoId) {
            if (confirm('确定要删除这个视频吗？')) {
                fetch(`/admin/video/${videoId}`, {
                    method: 'DELETE'
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        location.reload();
                    } else {
                        alert('删除失败：' + data.error);
                    }
                });
            }
        }
    </script>
</body>
</html> 